package com.kedacom.ctsp.authz.oauth2;

import com.kedacom.ctsp.authz.security.AuthzSecurityProperties;
import com.kedacom.ctsp.authz.security.AuthzWebSecurityConfigurerAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;

/**
 * @author: Songlin Ding
 * @Date: Created in 9:29 2018/4/25
 * @Description:
 */
@Configuration
@EnableConfigurationProperties(AuthzSecurityProperties.class)
public class OAuth2WebSecurityConfiguration extends AuthzWebSecurityConfigurerAdapter {

    @Autowired
    private AuthzSecurityProperties securityProperties;

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        super.configure(http);
        http.formLogin().loginPage("/login.html");
    }

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory factory) {
        StringRedisTemplate template = new StringRedisTemplate(factory);
        template.setValueSerializer(new JdkSerializationRedisSerializer());
        template.setHashValueSerializer(new JdkSerializationRedisSerializer());
        template.afterPropertiesSet();
        return template;
    }


}
